package cn.wolfcode.trip.base.util;

import com.wxapi.WxApiCall.WxApiCall;
import com.wxapi.model.RequestModel;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class SendVerify {
    private static Properties p;

    static {
        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("sendMsgKey.properties");
        p = new Properties();
        try {
            p.load(in);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 大宋登录验证码
     *
     * @param phoneNumber 登录的手机号码
     * @param verify      验证码
     * @return 成功与否
     */
    public static boolean sendLoginVerify(String phoneNumber, String verify) {
        try {
            RequestModel model = new RequestModel();
            String appkey = p.get("appkey").toString();
            String dxjkUrl = p.get("dxjkUrl").toString();
            model.setGwUrl(dxjkUrl);
            model.setAppkey(appkey);
            Map queryMap = new HashMap();
            queryMap.put("mobile", phoneNumber); //访问参数

            //短信接口只能使用备案的签名内容,不能修改其他
            queryMap.put("content", "【创信】你的验证码是：" + verify + "，3分钟内有效！"); //访问参数
            model.setQueryParams(queryMap);
            WxApiCall call = new WxApiCall();
            call.setModel(model);
            call.request();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

}
